#define __ethernetclientcpp__

#include "stdafx.h"

#include "ethernetclient.h"


// class EthernetClient ***********************************************************************


void EthernetClient::SentHTTPMessage()
{
	netDoneSend();
	_available = true;
}


void EthernetClient::stop()
{
	netClose();
	netClean();
	_connected = false;
	_available = false;
}

void EthernetClient::flush()
{
}

BOOL EthernetClient::connect(char * server, int port)
{
	if (netTCPclientOpen(server, port) == 0)
	{
		_connected = true;
		_available = false;
		_nextChar = ' ';
	}
	return _connected;
}

BOOL EthernetClient::connect(char * server)
{
	connect(server, 80);
	return _connected;
}

BOOL EthernetClient::available()
{
	_available = false;
	if (1 == 1) // (_nextChar != '}')
	{
		int res = netReceive(&_nextChar, 1);
		//If nothing received then done
		if (res == 1)
		{
			_available = true;
		}
	}
	return _available;
}

BOOL EthernetClient::connected()
{
	return _connected;
}


//Only need to implement this print for client as others call it
void EthernetClient::print(char * strn)
{
	int res = netSend(strn, strlen(strn));
}

void EthernetClient::println()
{
	EthernetClient::print(NL);
}

void EthernetClient::println(char * strn)
{
	EthernetClient::print(strn);
	EthernetClient::println();
}


void EthernetClient::print(int num)
{
	char strnn[50];
	sprintf(strnn, "%d", num);
	EthernetClient::print(strnn);
}

void EthernetClient::println(int num)
{
	EthernetClient::print(num);
	EthernetClient::println();
}

void EthernetClient::print(float num, int index)
{
	char strnn[50];
	sprintf(strnn,"%*.f",index,num);
	EthernetClient::print(strnn);
}

void EthernetClient::println(float num, int index)
{
	EthernetClient::print(num, index);
	EthernetClient::println();
}

char EthernetClient::read()
{

	return _nextChar;
}

#undef __ethernetclientcpp__
